import cv2 as cv
#   读取两幅图像
image1 = cv.imread('D:\img1.png')
image2 = cv.imread('D:\img2.png')
# print(image1.shape)
# print(image2.shape)
# cv.imshow('image1',image1)
# cv.imshow('image2',image2)
#   确保两张图片大小一致,img1.shape[1]和img1.shape[0]分别获取img1宽度和高度#image2 = cv.resize(image2, (image1.shape[1], image1.shape[0]))
#   确保两幅图像的大小相同
if image1.shape == image2.shape:
    #  使用cv.add()相加，饱和操作
    # cvadd_image = cv.add(image1, image2)
    #  直接相加，模运算,不推荐
    # add_image = image1 + image2
    #  显示结果
    # cv.imshow('cvAdd Images', cvadd_image)
    # cv.imshow('Add Images', add_image)

    # 使用cv.addWeighted()混合图像
    blended_image = cv.addWeighted(image1, 0.9, image2, 0.1, 0)
    cv.imshow('blended_image Images', blended_image)
    cv.waitKey(0)
    cv.destroyAllWindows()
else:
    print("图片必须相同的大小和类型.")